package com.atliuzu.utils;

import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author : songyuan
 * @Description :
 * Date : 2022/8/20 15:20
 * @Version : 1.0
 */
public class KeywordUtil {

    public static List<String> spiltKeyWord(String keyWord) throws IOException {

        //储存切分后的单次集合
        ArrayList<String> list = new ArrayList<>();

        //读入搜索关键字
        StringReader stringReader = new StringReader(keyWord);

        //创建ik分词器对象   true 为smart分词格式
        IKSegmenter ikSegmenter = new IKSegmenter(stringReader, true);

        //和io中 reader读取的方式不一样
        Lexeme next = ikSegmenter.next();
        while (next != null) {
            list.add(next.getLexemeText());
            next = ikSegmenter.next();
        }

        return list;
    }

}
